package com.health.activity.qyinfo;

import java.io.IOException;

import com.health.NovaActivity;
import com.health.R;
import com.health.tools.LinePathView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * 签名
 */
public class QianMingActivity extends NovaActivity implements OnClickListener {
	private static String TAG = "QianMingActivity";
	public static final String SIGNNAME_HEAD = "signNameHead";
	// 命名规则： 身份证号_签约时间_用户类型_创建时间时分秒_随机数.png[用户类型： 1 医生 2 患者 3 其他图片]
	public static String signNameHead = "";
	Button btn_up;
	LinePathView linePathView;
	Button btn_clear;
	String path;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_qian_ming);
		findViews();
		setListeners();
		setData();
	}

	@Override
	public void findViews() {
		btn_up = (Button) findViewById(R.id.btn_up);
		btn_clear = (Button) findViewById(R.id.btn_clear);
		linePathView = (LinePathView) findViewById(R.id.line_path_view);
	}

	@Override
	public void setListeners() {
		btn_up.setOnClickListener(this);
		btn_clear.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.btn_up) {
			try {
				// path = linePathView.save();
				// showTextDialog("保存成功");
				path = linePathView.saveBySign(signNameHead);
				Intent intent = new Intent();
				// Intent intent = getIntent();
				Log.e(TAG, "签名地址：" + path);
				intent.putExtra("filePath", path);
				setResult(RESULT_OK, intent);
				finish();
			} catch (IOException e) {
				showTextDialog("保存失败");
				e.printStackTrace();
			}
		} else if (v.getId() == R.id.btn_back) {
			finish();
		} else if (v.getId() == R.id.btn_clear) {
			linePathView.clear();
			showTextDialog("清除签名");
		}
	}

	/**
	 * 设置数据
	 * 
	 * @author 王婷婷
	 * @date 2017年12月7日 上午10:00:26
	 */
	private void setData() {
		if (getIntent().hasExtra(SIGNNAME_HEAD)) {
			signNameHead = getIntent().getStringExtra(SIGNNAME_HEAD);
		} else {
			signNameHead = "";
		}
	}
}